<template>
    <div class="news-list">
        <NuxtLink
            class="news-item"
            :to="`/news/${item.id}.html`"
            v-for="item in renderList"
            :key="item.id"
        >
            <div class="news-item__left">
                <div class="news-item__date">
                    <p class="date">
                        {{ formatDate(item.createtime, "DD") }}
                    </p>
                    <p class="year">
                        {{ formatDate(item.createtime, "YYYY.MM") }}
                    </p>
                </div>

                <div class="news-item__line">
                    <div class="bg"></div>
                </div>
            </div>
            <div class="news-item__right">
                <div class="news-item__title">
                    {{ item.title }}
                </div>
                <div class="news-item__desc">
                    {{ item.subtitle }}
                </div>
            </div>

            <img
                class="cover-image"
                :src="
                    item.cover_image ||
                    'https://yzpt-resources.oss-cn-hangzhou.aliyuncs.com/web/images/home/home-swiper-1.jpg?x-oss-process=image/watermark,image_d2F0ZXIvd2F0ZXJtYXJrLnBuZw'
                "
            />
        </NuxtLink>
    </div>
    <PageSeeMoreM
        v-if="props.list.length > pagination.size * pagination.page"
        @next="pagination.page += 1"
    />
</template>
<script setup>
const props = defineProps({
    list: {
        type: Array,
        default: () => [],
    },
});

const pagination = reactive({
    size: 10,
    page: 1,
});

const renderList = computed(() => {
    return props.list.slice(0, pagination.page * pagination.size);
});
</script>
<style lang="scss" scoped>
.news-list {
    display: flex;
    flex-wrap: wrap;
    padding: 0 15px 15px;

    .news-item {
        position: relative;
        display: flex;
        width: 345px;
        height: 135px;
        padding: 15px 17px 0 20px;
        border-radius: 4px;
        box-shadow: 0px 0px 10px 0px rgba(1, 23, 86, 0.1);
        margin-top: 15px;
        border: 1px solid transparent;
        background-color: #fff;
        text-decoration: none;

        &:first-of-type {
            margin-top: 0;
        }

        .cover-image {
            width: 260px;
            height: 100%;
            position: absolute;
            right: 0;
            top: 0;
            object-fit: cover;
            opacity: 0;
            transition: all 0.2s;
        }

        &:last-of-type {
            margin-bottom: 0;
        }

        &:hover {
            border-color: #5085fb;

            .news-item__title {
                color: #5085fb;
            }

            .cover-image {
                opacity: 1;
            }

            .news-item__line {
                .bg {
                    height: 100%;
                }
            }

            .news-item__date {
                .date {
                    color: #5085fb;
                }

                .year {
                    color: #5085fb;
                }
            }
        }

        &__left {
            margin-right: 27px;
        }

        &__date {
            text-align: center;
            font-family: "DINCond_Regular";

            .date {
                color: #333;
                font-size: 32px;
                font-weight: bold;
                line-height: 1;
            }

            .year {
                font-size: 16px;
                color: #999;
                margin-top: 5px;
            }
        }

        &__line {
            width: 1px;
            height: 40px;
            background-color: #ddd;
            margin: 10px auto 0;

            .bg {
                width: 100%;
                height: 0%;
                background-color: #5085fb;
                transition: all 0.4s linear;
            }
        }

        &__title {
            height: 34px;
            line-height: 17px;
            font-size: 15px;
            color: #333333;
            margin-bottom: 15px;

            display: -webkit-box;
            overflow: hidden;
            text-overflow: ellipsis;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
        }

        &__desc {
            font-size: 12px;
            line-height: 16px;
            color: #666;
            display: -webkit-box;
            overflow: hidden;
            text-overflow: ellipsis;
            -webkit-line-clamp: 3;
            -webkit-box-orient: vertical;
        }
    }
}
</style>
